<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .container {
            /* border: 1px solid; */
            display: flex;
            align-items: center;
            position: absolute;
            bottom: 20%;
            left: calc(50% - 150px);
        }

        textarea {
            height: 60px;
            resize: none;
        }

        [type="button"] {
            margin-left: 10px;
        }

        /* message1 */
        .message1 {
            width: 100px;
            min-height: 100px;
            border: 1px dashed #ccc;
            padding: 10px;
            word-break: break-all;
            position: absolute;
        }

        .message1::first-letter {
            margin-left: 25px;
        }

        .message1::before {
            content: '';
            display: block;
            width: 70px;
            height: 20px;
            background-color: rgba(0, 0, 255, .5);
            position: absolute;
            left: -10px;
            top: 5px;
            transform: rotate(-30deg);
        }

        /* message2 */
        .message2 {
            width: 150px;
            min-height: 100px;
            border: 1px dashed #ccc;
            padding: 10px;
            word-break: break-all;
            position: absolute;
        }

        .message2::before {
            content: 'message';
            text-transform: uppercase;
            display: block;
            text-align: center;
            background-color: rgba(0, 0, 0, .5);
            color: #fff;
            letter-spacing: 10px;
        }

        /* message3 */
        .message3 {
            width: 150px;
            min-height: 100px;
            border: 1px dashed #ccc;
            padding: 10px;
            word-break: break-all;
            position: absolute;
            border-bottom-left-radius: 20px;
        }

        .message3::before {
            content: 'message';
            text-transform: uppercase;
            display: block;
            /* text-align: center; */
            background-color: rgba(0, 0, 0, .5);
            color: #fff;
            text-indent: 5px;

        }

        .message3:after {
            content: '';
            display: block;
            width: 10px;
            height: 10px;
            border-radius: 50%;
            background-color: #fff;
            position: absolute;
            right: 25px;
            top: 16px;
            box-shadow: 2px 0 2px #000;
        }
    </style>
</head>

<body>
    <div class='container'>
        <textarea placeholder="许愿!5元一次!不灵很正常"></textarea>
        <input type="button" value='许愿'>
    </div>


    

    <script src="../tools.js"></script>
    <script>
        const btn = document.querySelector('[type="button"]'); // 按钮
        const ipt = document.querySelector('textarea'); // 输入框

        const styles = ['message1', 'message2', 'message3'];

        btn.onclick = function () {
            let div = document.createElement('div');
            div.innerText = ipt.value;
            document.body.appendChild(div);

            let randomIndex = random(2);
            div.className = styles[randomIndex];
            div.style.cssText = `
                background: rgb(${random(255)},${random(255)},${random(255)});
                position: absolute;
                left: -200px;
                top: 0px;
            `;
            let x = innerWidth, y = random(innerHeight - 200);
            let timer = setInterval(function () {
                div.style.cssText += `
                    position: absolute;
                    left: ${x -= 5}px;
                    top: ${y}px;
                `;
                if (x < 0) {
                    clearInterval(timer);
                    document.body.removeChild(div);
                }
            }, 100);
        }




    </script>
</body>

</html>